// JavaScript Document
var xmlDoc="";
var call_id=""; //通话唯一标识；
var charnum=new Array();
function call(callarr){
   var obj=document.getElementsByName(callarr);
   var leng=obj.length;
   var phone_book="";
   for(var i=0;i<leng;++i){
	   if(obj.item(i).checked==true){
		   phone_book+=","+obj.item(i).value;
		   }
	   }
if(phone_book==""){alert("没有选择打电话用户");return 0;}
phone_book=phone_book.substr(1,phone_book.length-1);
		$.ajax({
			type:"POST",
			url:"public/talk.php",
			cache:false,
			data:"act=convokeMeeting&phoneNo="+phone_book,
			success:function(data){
				if(typeof(data)=="undefined"){
					alert("还没有开通这个业务");
					}else{
				var data_arr=data.split(",");
				if(data_arr[0]!='100'){
					alert("没有拨打成功");
					}else{
				call_id=data_arr[1];}
			}}
		});

	}
	
function stop_call(){
	if(call_id==""){
		alert("没有在通话");
		return 0;
		}		
		$.ajax({
			type:"POST",
			url:"public/talk.php",
			cache:false,
			data:"act=endMeeting&number="+call_id,
			success:function(data){
			if(data!='100'){
				alert("没有结束对话");
				}else{
			call_id="";
			}	
			}
		});
	}
	
	
function post_message(chebox,text){
   var obj=document.getElementsByName(chebox);
   var leng=obj.length;
   var phone_book="";
   for(var i=0;i<leng;++i){
	   if(obj.item(i).checked==true){
		   phone_book+=","+obj.item(i).value;
		   }
	   }
if(phone_book==""){alert("没有选择打电话用户");return 0;}
if(document.getElementById(text).value==""){
	alert("没有输入要发送的信息");return 0;
	}
phone_book=phone_book.substr(1,phone_book.length-1);
		$.ajax({
			type:"POST",
			url:"public/msg.php",
			cache:false,
			data:"phoneNo="+phone_book+"&msg="+document.getElementById(text).value,
			success:function(data){
				if(data==1){
					document.getElementById('msg').innerHTML="<span style='color:#06F'>发送成功</span>";
					}else{
						if(data==2){
							document.getElementById('msg').innerHTML="<span style='color:#F00'>查看输入是否正确</span>";
							}else{
					  document.getElementById('msg').innerHTML="<span style='color:#F00'>发送失败</span>";}
			}}
		});

	return 0;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	function call_one(callarr){
		$.ajax({
			type:"POST",
			url:"public/talk.php",
			cache:false,
			data:"act=convokeMeeting&phoneNo="+callarr,
			success:function(data){
				if(typeof(data)=="undefined"){
					alert("还没有开通这个业务");
					}else{
				var data_arr=data.split(",");
				if(data_arr[0]!='100'){
					alert("没有拨打成功");
					}else{
				call_id=data_arr[1];}
			}}
		});

	}
	
function stop_call_one(){
	if(call_id==""){
		alert("没有在通话");
		return 0;
		}
		
		$.ajax({
			type:"POST",
			url:"public/talk.php",
			cache:false,
			data:"act=endMeeting&number="+call_id,
			success:function(data){
			if(data!='100'){
				alert("没有结束对话");
				}else{
			call_id="";
			}	
			}
		});
	}
	
	
	
	
function post_message_one(chebox,text){
	   var phone_book=chebox;
if(phone_book==""){alert("没有选择打电话用户");return 0;}
if(document.getElementById(text).value==""){
	alert("没有输入要发送的信息");return 0;
	}
phone_book=phone_book.substr(1,phone_book.length-1);
		$.ajax({
			type:"POST",
			url:"public/msg.php",
			cache:false,
			data:"phoneNo="+phone_book+"&msg="+document.getElementById(text).value,
			success:function(data){
				if(data==1){
					document.getElementById('msg').innerHTML="<span style='color:#06F'>发送成功</span>";
					}else{
						if(data==2){
							document.getElementById('msg').innerHTML="<span style='color:#F00'>查看输入是否正确</span>";
							}else{
					  document.getElementById('msg').innerHTML="<span style='color:#F00'>发送失败</span>";}
			}}
		});

	return 0;
	}




function textarea_is(obj){
	if(obj.value.length>60){
		obj.value=obj.value.substr(0,60);
		alert("长度超出60字符");
		}
	}






function SOS(){
	prompt_1();
	function prompt_1(){
        if(window.XMLHttpRequest) {                                                         //Mozilla浏览器
            xmlHttp=new XMLHttpRequest();
                if(xmlHttp.overrideMimeType) {                                                  //设置MIME类别
                   xmlHttp.overrideMimeType("text/xml");
                }
            } else if(window.ActiveXObject) {                                                   //IE浏览器
                try {
                    xmlHttp=new ActiveXObject("Msxml2.XMLHttp");
                }
                catch(e) {
                    try {
                        xmlHttp=new ActiveXobject("Microsoft.XMLHttp");
                    }
                    catch(e){
                    }
                }
                }
		 var url="js/SOS.php";
		 xmlHttp.onreadystatechange=handle_f;
		 xmlHttp.open("GET",url,true);
		 xmlHttp.send(null);
		}
	function handle_f(){
		if(xmlHttp.readyState==4){
			if(xmlHttp.status==200){
				xmlDoc=xmlHttp.responseText;
				if(typeof(xmlDoc)=='undefined'){
					return 0;
					}
						if(xmlDoc!=''){
						   document.getElementById('SOS').getElementsByTagName("span").item(0).style.color="#FF0000";
						   document.getElementById('SOS').getElementsByTagName("a").item(0).style.color="#FF0000";
						   if(!+[1,])
						   document.getElementById('mplay').play();		
							}
			          }
								  else{
				                   alert("执行出现问题"+xmlHttp.statusText);
								   }
				}
				}
	setTimeout(SOS,10000);
	}
setTimeout(SOS,1000);
		
function c(){
			$.ajax({
			type:"POST",
			url:"public/listen.php",
			cache:false,
			data:"option=c",
			success:function(data){
				if(typeof(data)=='undefined'){
					return 0;
					}
						if(data!='N'){
						   document.getElementById('Location').getElementsByTagName("span").item(0).style.color="#FF0000";
						   document.getElementById('Location').getElementsByTagName("a").item(3).style.color="#FF0000";
						   charnum=[];
						   charnum.push(data.split('_')[0]);
						   charnum.push(data.split('_')[1]);
				}
				setTimeout(c,10000);
			}
		});
	}
setTimeout(c,1000);

function QueryInfoStop(){
			$.ajax({
			type:"POST",
			url:"public/listen.php",
			cache:false,
			data:"option=c&a="+charnum[0],
			success:function(data){
				if(typeof(data)=='undefined'){
					return 0;
					}
						if(data!='N'){
            	 charnum=[];
						   document.getElementById('Location').getElementsByTagName("span").item(0).style.color="#666";
						   document.getElementById('Location').getElementsByTagName("a").item(3).style.color="#666";
						alert("停止成功");
						}else{
							alert("停止失败");
							}
				}
		});
}